﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<QuestionInputModels>" %>

<%@ Import Namespace="SDT.Lib.Helpers" %>
<%@ Import Namespace="SDT.Lib.Paging" %>
<%@ Import Namespace="SDT.Admin.ViewModels" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Chi tiết câu hỏi
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%if (ViewData["MessageInfo"] == null)
      { %>
    <% using (Html.BeginForm("Edit", "Question", FormMethod.Post, new
       {
           id = "adminForm",
           enctype = "multipart/form-data"
       }))
       {%>
    <%= Html.ValidationSummary(true)%>
    <fieldset>
        <legend>Thông tin chi tiết câu hỏi</legend>
        <table class="admintable" width="100%">
            <tbody>
                <tr>
                    <td class="key">
                        Chuyên mục
                    </td>
                    <td>
                        <%= Model.Question.CatID.HasValue ? Model.Question.QuestionCategory.Name : "--"%>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        Tiêu đề
                    </td>
                    <td>
                        <%= Model.Question.Title %>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        Nội dung
                    </td>
                    <td>
                        <%= Model.Question.QuestionContent %>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        Metadescription
                    </td>
                    <td>
                        <%= Model.Question.MetaDescription %>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        Metakeyword
                    </td>
                    <td>
                        <%= Model.Question.MetaKeyword %>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        Metatag
                    </td>
                    <td>
                        <%= Model.Question.MetaTag %>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        Trạng thái hiển thị
                    </td>
                    <td>
                        <%= Html.RadioButton("PubYN", true, Model.Question.PubYN)%>
                        Đăng tin
                        <%= Html.RadioButton("PubYN", false, !Model.Question.PubYN)%>
                        Không đăng
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        Trạng thái kiểm tra
                    </td>
                    <td>
                        <%= Html.RadioButton("CheckYN", true, Model.Question.CheckYN)%>
                        Đã kiểm tra
                        <%= Html.RadioButton("CheckYN", false, !Model.Question.CheckYN)%>
                        Chưa kiểm tra
                    </td>
                </tr>
            </tbody>
        </table>
    </fieldset>
    <fieldset>
        <legend>Thông tin các câu trả lời</legend>
        Hiện có <%= Model.Question.nAnswers %> câu trả lời.<br />
        <% if (Model.ListAnswer != null && Model.ListAnswer.Count() > 0)
           {
               foreach (var a in Model.ListAnswer)
               {
               %>
               <div style="border-bottom: 1px dashed #999;" ></div>
        <table class="admintable" width="100%">
            <tbody>
                <tr>
                    <td class="key">
                        Nội dung câu trả lời
                    </td>
                    <td>
                        <%= a.Answers %>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        Ngày gửi
                    </td>
                    <td>
                        <%= a.AddDate %>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        Người gửi
                    </td>
                    <td>
                        <%= string.IsNullOrEmpty(a.AnswerName) ? a.aspnet_User.UserName : a.AnswerName %>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        Email
                    </td>
                    <td>
                        <%= string.IsNullOrEmpty(a.AnswerEmail) ? a.aspnet_User.aspnet_Membership.Email: a.AnswerEmail%>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        Trạng thái
                    </td>
                    <td>
                        <img style="cursor: pointer;" alt="" id="imgPubYN_<%= a.ID %>" onclick="ChangePubYN(<%= a.ID %>);" value="<%= a.PubYN.Value %>"
                        src="<%= a.PubYN.HasValue && a.PubYN.Value ? "/Images/icon-32-apply.png" : "/Images/icon-32-cancel.png" %>" />
                    </td>
                </tr>
                 <tr>
                <td colspan="2" align="center">
                    <input class ="DeleteAnswer" type="button" id="<%=a.ID %>" value ="Xóa câu trả lời" />
                    <input class ="EditAnswer" type="button" id="<%=a.ID %>" value ="Sửa câu trả lời" />
                </td>
            </tr>
            </tbody>
        </table>
        <%}
           } %>
        <table width="100%">
            <tr>
                <td align="center">
                    <input type ="hidden" value ="<%=Model.ListAnswer.PageNumber %>" class= "hdnpage" />
                    <div class="pager">
                        <%= Html.Pager(Model.ListAnswer.PageSize, Model.ListAnswer.PageNumber, Model.ListAnswer.TotalItemCount)%>
                    </div>
                </td>
            </tr>
        </table>
    </fieldset>
    <%}
      } %>

    <script type="text/javascript">
    	$(document).ready(function() {
    		$("#adminForm").validate();
    		$(".DeleteAnswer").click(function() {
    			var CurrentAnswer = $(this).attr("id");
    			var CurrentPage = $(".hdnpage").val();
    			if (confirm("Bạn có chắc muốn xóa câu trả lời này không")) {
    				window.location = "/Question/DeleteAnswer/{0}?page={1}".replace("{0}", CurrentAnswer).replace("{1}", CurrentPage);
    			}
    		});
    		$(".EditAnswer").click(function() {
    			var CurrentAnswer = $(this).attr("id");
    			var CurrentPage = $(".hdnpage").val();
    			window.location = "/Question/EditAnswer/{0}?page={1}".replace("{0}", CurrentAnswer).replace("{1}", CurrentPage);
    		});
    	});
        tinyMCE.init({
            mode: "exact",
            elements: "QuestionContent",
            theme: "advanced",
            plugins: "spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,paste,imagemanager",
            theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
            theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,cleanup,help,code,|,insertdate,inserttime,preview",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_statusbar_location: "bottom",
            paste_use_dialog: false,
            paste_auto_cleanup_on_paste: true,
            paste_convert_headers_to_strong: false,
            paste_strip_class_attributes: "all",
            paste_remove_spans: true,
            paste_remove_styles: true
        });

        function ChangePubYN(id) {
            var obj = $("#imgPubYN_" + id);
            ApplyChangeYN("/AjaxData/UpdateAnswerPubYN/" + id + '/' + obj.attr("value"), id, obj);
        }
    </script>

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Toolbar" runat="server">
    <td>
        <%= Html.Toolbar("Trả lời", "/Question/Answer/" + Model.Question.ID, "word")%>
    </td>
    <td>
        <%= Html.Toolbar("Sửa", "/Question/Edit/" + Model.Question.ID, "edit") %>
    </td>
    <td>
        <%= Html.Toolbar("Xoá", "/Question/Delete/" + Model.Question.ID, "delete")%>
    </td>
    <td>
        <%= Html.Toolbar("Quay lại", "/Question", "back")%>
    </td>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Header" runat="server">
    Chi tiết câu hỏi
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="Message" runat="server">
    <%=ViewData["MessageInfo"]!=null? "<p class='perror'>"+Html.Encode(ViewData["MessageInfo"])+"</p>":string.Empty%>
</asp:Content>
